// pages/mine/mine.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    intake: 0,
    sum: 2000,
    integral: 0,
    userinfo: '',
    isShow: 'none',
    msgData: [
      "我的信息",
      "识别记录",
      "联系我们",
      "意见反馈",
      "帮助中心",
    ],
    navList: [{
        title: '我的收藏',
        img: '../../images/collect_y.png'
      },
      {
        title: '美食大转盘',
        img: '../../images/zp.png'
      },
      {
        title: '扫描记录',
        img: '../../images/record.png'
      },
    ],
  },
  goToZP: function () {
    wx.navigateTo({
      url: '../zhuanpan/zhuanpan',
    })
  },
  goToScan: function () {

    this.changeImage()
    wx.navigateTo({
      url: '../record/record',
    })
  },
  shouquan() {

    wx.getUserProfile({
      desc: '需要获取用户数据才能使用',
      success: res => {
        wx.setStorage({
          data: {
            userxx: res.userInfo,
            token: ''
          },
          key: 'user',
        })
        var user = wx.getStorage({
          key: 'user',
        })

        var userxx = wx.getStorageSync('user')
        console.log(userxx);

        this.setData({
          isShow: 'none'
        })
      },
      fail: res => {},
    })
  },
  biaodan: function (e) {

    this.changeImage()
    console.log(e.currentTarget.dataset.i);
    var i = e.currentTarget.dataset.i
    if (i == 0) {
      wx.navigateTo({
        url: '/pages/biaodan/biaodan',
      })
    } else if (i == 1) {
      this.goToScan()
    } else if (i == 2) {
      this.lianxi()
    } else if (i == 3) {
      this.fankui()
    } else if (i == 4) {
      this.help()
    }

  },
  goToIntegralDetail: function (e) {
    if (this.data.userinfo == undefined || this.data.userinfo == '') {
      wx.navigateTo({
        url: '../denglu/denglu?type=mine',
      })
      return
    }
    wx.navigateTo({
      url: '../integralDetail/integralDetail',
    })
  },
  shoucang: function () {
    wx.navigateTo({
      url: '/pages/collection/collection',
    })
  },
  lianxi: function () {
    wx.navigateTo({
      url: '/pages/lianxi/lianxi',
    })
  },
  fankui: function () {
    wx.navigateTo({
      url: '/pages/proposal/proposal',
    })
  },
  help: function () {
    wx.navigateTo({
      url: '/pages/help/help',
    })
  },
  changeImage: function (e) {
    console.log(this.data.userinfo);
    if (this.data.userinfo == undefined || this.data.userinfo == '') {
      wx.navigateTo({
        url: '../denglu/denglu?type=mine',
      })
    }
  },
  onLoad: function (options) {

  },
  onShow: function () {
    var user = wx.getStorageSync('user');

    console.log(user);
    console.log(this.data.isShow);
    if (user == null || user == '') {
      this.setData({
        intake: 0
      })
      console.log(this.data.isShow);
    } else {
      this.setData({
        isShow: 'none'
      })
    }
    console.log(user);
    this.setData({
      userinfo: user.userxx
    })
    var zzw = wx.getStorageSync('zzw');
    if (zzw == undefined || zzw == "")
      return
    console.log(zzw);
    var intake = 0
    for (const key in zzw.data[zzw.count]) {
      if ((key == 0 || key == 2) && zzw.data[zzw.count][key].isFinish) {
        intake += 500
      } else if ((key == 1) && zzw.data[zzw.count][key].isFinish) {
        intake += 1000
      }
    }
    this.setData({
      intake: intake == "" ? 0 : intake
    })
  },
  onHide: function () {
    wx.setStorageSync('intake', this.data.intake)
  },
})